local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local theme = require("theme")
local dpi	= require("beautiful.xresources").apply_dpi

local caps = {}

caps.widget = wibox.widget{
	{
		{
			{
				{
					{
						image		= theme.caps_on_icon,
						forced_width = dpi(16),
						forced_height = dpi(17),
						widget		= wibox.widget.imagebox,
					},
					valign = "center",
					halign = "center",
					widget  = wibox.container.place,
				},
				wibox.container.margin(_,dpi(7)),
				{
					{
						text		= "Cpas Lock", 
						font        = theme.caps_widget_on_font,
						widget		= wibox.widget.textbox,
					},
					valign = "center",
					halign = "center",
					widget  = wibox.container.place,
				},
				layout = wibox.layout.fixed.horizontal,
			},
			left   = dpi(15),
			right  = dpi(15),
			widget = wibox.container.margin,
		},
		bg = theme.caps_on_bg,
		fg = theme.caps_on_fg,
		shape = function(cr, width, height)
			gears.shape.rounded_rect(cr, width, height, theme.widget_radius)
		end,
		widget = wibox.container.background,
	},
	visible = false,
	margins = theme.widget_margins,
	widget	= wibox.container.margin,
}



function caps:on()
	--self.popup.visible = true
	self.widget.visible = true
end

function caps:off()
	--self.popup.visible = false
	self.widget.visible = false
end


function caps:setup()
	--caps.popup = awful.popup{
	--	widget = caps.widget,
	--	border_color	= theme.popup_border_color,
	--	border_width	= 0,  --theme.popup_border_width,
	--	visible			= false,
	--	fg              = theme.caps_on_fg,
	--	bg              = theme.caps_on_bg,
	--	ontop			= true,
	--	hide_on_right_click = false,
	--	shape			= function(cr, width, height)
	--		gears.shape.rounded_rect(cr, width, height, dpi(50))
	--	end,
	--	placement		= function(wdg,args)  
	--		awful.placement.bottom(wdg, {margins = { bottom = dpi(150)}}) 
	--	end,
	--}
	awful.spawn.with_shell("pgrep caps_monitor &>/dev/null || " .. os.getenv("HOME") .. "/.config/awesome/widgets/caps/scripts/caps_monitor")
	return self.widget
end


return caps
